package com.mediacloud.app.newsmodule.fragment.audio.live;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.mediacloud.app.model.news.ProgramListItem;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.fragment.video.live.LiveProgramTableFragment;
import com.mediacloud.app.newsmodule.model.SimpleNavigateItem;
import com.mediacloud.app.reslib.util.AppFontToolKt;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 音频直播节目单管理器
 * @author x
 *
 */
public class AudioLiveProgramTable extends LiveProgramTableFragment
{
	@Override
	protected void getProgramList() {
	}
    @Override
	public Fragment getViewContentFragment(SimpleNavigateItem catalogItem)
	{
		AudioProgramItemFragment fragment=new AudioProgramItemFragment();
		fragment.closeListener=clickListener;
		fragment.liveTableIndex=catalogItem.index;
		boolean isFullScreen = getFragmentArguments().getBoolean("fullScreen");
		Bundle bundle=new Bundle();
		bundle.putParcelable("data", catalogItem);
		bundle.putBoolean("fullScreen", isFullScreen);
        View textViewX = mRootView.findViewById(R.id.tv_audio_live_program_title);
        textViewX.setVisibility(View.VISIBLE);
        View imageClose = textViewX.findViewById(R.id.image_close);
        View tvClose = mRootView.findViewById(R.id.tv_close);
        imageClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null) {
                    clickListener.onClick(v);
                }
            }
        });
        tvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null) {
                    clickListener.onClick(v);
                }
            }
        });

		if(programListItems!=null&&programListItems.size()==navigateItems.size())
		{
			List<ProgramListItem> programList=programListItems.get(catalogItem.index).programList;
			if(programList==null)
				programList=new ArrayList<ProgramListItem>();
			bundle.putSerializable(Program, (Serializable) programList);
		}
		fragment.setArguments(bundle);
		return fragment;
	}


    @Override
    public int getLayoutResID() {
        boolean isFullScreen = getFragmentArguments().getBoolean("fullScreen");
        if (!isFullScreen) {
            return R.layout.aappfactory_audio_live_program_half;
        }
        return super.getLayoutResID();
    }

    View.OnClickListener clickListener;

    public void setOnCloseBtnClickListenser(View.OnClickListener clickListener) {
        this.clickListener = clickListener;
    }
}